﻿
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">

    <link rel="stylesheet" type="text/css" href="~/layui/css/layui.css" />
    <script src="~/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="~/layui/jquery-3.4.1.js" type="text/javascript" charset="utf-8"></script>
    <title>会员等级管理</title>
    <style type="text/css">
        .layui-input {
            margin-top: 5px;
            height: 30px
        }

        .layui-form-label {
            width: auto;
            padding: 5px 10px;
            margin-top: 5px;
        }
    </style>
</head>
<body>
    <div>
        <div class="layui-btn-container">
            <button type="button" id="new" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe654;新增</i></button>
            <button type="button" class="layui-btn layui-btn-primary layui-btn-sm"><i class="layui-icon">&#xe640;删除</i></button>
        </div>
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">等级名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input" id="levelName">
                </div>
                <button id="searh" type="button" class="layui-btn layui-btn layui-btn-sm" style="margin-top: 5px;"><i class="layui-icon">&#xe615;搜索</i></button>
            </div>
        </form>
        <table class="layui-inline" lay-filter="table" id="cardList"></table>
    </div>


    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script>

    </script>
    <script>

        layui.use(['table', 'layer'], function () {
            var table = layui.table,
                layer = layui.layer;

            //行内工具栏
            table.on('tool(table)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            type: "get",
                            url: "/Member/MemcardDelResult",
                            data: { id: data.CL_ID },
                            success: function (data) {
                                if (data == '删除成功') {
                                    layer.msg(data, { icon: 1 })
                                    obj.del();
                                } else {
                                    layer.msg(data, { icon: 2 })
                                }
                            },
                            error: function (data) {
                                layer.msg('删除失败', { icon: 2 })
                            }
                        })
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    // window.location.href='update.aspx?id=' + data.U_ID
                    //layer.alert('编辑行：<br>' + JSON.stringify(data))
                    var id = data.CL_ID;
                    layer.open({
                        type: 2,
                        content: ['/Member/MemcardEdit/' + id + '', 'no'],
                        area: ['500px', '400px'],
                        offset: ['100px', '400px'],
                        skin: 'layui-layer-molv',
                        maxmin: true,
                        id: 'add',
                        end: function () { table.reload('cardList') }
                    });
                }
            });
            //添加按钮点击事件
            $('#new').click(function () {
                layer.open({
                    type: 2,
                    content: ['/Member/MemcardAdd', 'no'],
                    //content: ['/Member/Add', 'no'],
                    area: ['500px', '400px'],
                    offset: ['100px', '400px'],
                    skin: 'layui-layer-molv',
                    maxmin: true,
                    id: 'add',
                    end: function () { table.reload('cardList') }
                });
            })
            //搜索按钮的点击事件
            $('#searh').on('click', function () {
                //获取输入框的值
                var levelName = $('#levelName').val();
                //表格重载，并传回服务器参数
                table.reload('cardList', {
                    //提交方式 Post
                    method: 'post',
                    //传回服务器的参数
                    where: {
                        'CL_LevelName': levelName
                    }
                });
            })
            //载入表格
            table.render({
                elem: '#cardList',
                url: 'http://115.157.168.116:801/api/values',
                //url: '/CardLevels/CardLIvelsResult',
                //开启分页
               page: 'true',
                method:"post",
                cols: [
                    [{
                        type: 'checkbox'
                    }, {
                        field: 'CL_ID',
                        width: 150,
                        title: '等级编号',
                        sort: true
                    },
                    {
                        field: 'CL_LevelName',
                        width: 150,
                        title: '等级名称',
                        sort: true
                    },
                    {
                        field: 'CL_NeedPoint',
                        width: 150,
                        title: '所需最大积分',
                        sort: true
                    },
                    {
                        field: 'CL_Point',
                        width: 150,
                        title: '扣分比例',
                        sort: true
                    },
                    {
                        field: 'CL_Percent',
                        width: 150,
                        title: '折扣比例',
                        sort: true,
                    },
                    {
                        width: 120,
                        title: '操作',
                        sort: true,
                        toolbar: '#barDemo'
                    }
                    ]
                ]
            });
        })



    </script>
</body>
</html>
